package net.cyue.web.easyquery.provider.http.servlet;

import jakarta.servlet.ServletContext;
import net.cyue.web.easyquery.core.http.adapter.AbstractHTTPServer;
import net.cyue.web.easyquery.core.util.TaskUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ServletHTTPServer extends AbstractHTTPServer<ServletContext> {

    private final Logger logger = LoggerFactory.getLogger(this.toString());

    private ServletContext context;

    public ServletHTTPServer() {
        this(null);
    }
    public ServletHTTPServer(ServletContext context) {
        super();
        this.context = context;
        TaskUtil.addTask(HTTPServletProviderTaskType.INIT, (servletContext) -> {
            this.logger.info("初始化 HTTPServer@{}", this.getClass().getSimpleName());
            this.context = servletContext;
            TaskUtil.runTask(HTTPServletProviderTaskType.ADD_ROUTE, servletContext);
        });
    }

    @Override
    public ServletContext getPrototype() {
        return this.context;
    }
}
